﻿/// <reference path="httpRequester.js" />
var controls = controls || {};
(function (c) {
    var TableView = Class.create({
        init: function (itemsSource) {
            if (!(itemsSource instanceof Array)) {
                throw "The itemsSource of a TableView must be an array!";
            }

            this.cols = 1;
            this.itemsSource = itemsSource;
        },
        render: function (template) {
            //console.log(this.itemsSource);
            var elementTable = document.createElement("table");
            var rows = this.itemsSource.length / this.cols;
            for (var row = 0; row < rows; row++) {
                var currentRow = document.createElement("tr");

                for (var col = 0; col < this.cols; col++) {
                    var currentCol = document.createElement("td");
                    currentCol.innerHTML = template(this.itemsSource[row + col]);
                    currentRow.appendChild(currentCol);
                }

                elementTable.appendChild(currentRow);
            }

            return elementTable.outerHTML;
        }
    });

    c.getTableView = function (cols, itemsSource) {
        return new TableView(cols, itemsSource);
    }
}(controls || {}));

